package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.ConsultantLevel;
import com.hs.service.ConsultantLevelService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("consultantlevel")
public class ConsultantLevelController {
    @Autowired
    private ConsultantLevelService consultantLevelService;
    @PostMapping
    public R addConsultantLevel(@RequestBody ConsultantLevel consultantLevel) {
        Integer i = consultantLevelService.addConsultantLevel(consultantLevel);
        if (i > 0) {
            return R.ok();
        }else {
            return R.fail("失败");
        }
    }
    @DeleteMapping("{id}")
    public R deleteConsultantLevel(@PathVariable("id") Integer id) {
        Integer i = consultantLevelService.deleteConsultantLevel(id);
        if (i > 0) {
            return R.ok();
        }else {
            return R.fail("失败");
        }
    }
    @PutMapping
    public R updateConsultantLevel(@RequestBody ConsultantLevel consultantLevel) {
        Integer i = consultantLevelService.updateConsultantLevel(consultantLevel);
        if (i > 0) {
            return R.ok();
        }else {
            return R.fail("失败");
        }
    }
    @GetMapping("{id}")
    public R getConsultantLevelById(@PathVariable("id") Integer id) {
        ConsultantLevel consultantLevelById = consultantLevelService.getConsultantLevelById(id);
        return R.ok(consultantLevelById);
    }
    @GetMapping("page")
    public R getConsultantLevelByPage(@RequestParam(defaultValue = "1",required = false) Integer pageNum,
                                      @RequestParam(defaultValue = "5",required = false) Integer pageSize) {
        PageInfo<ConsultantLevel> consultantLevelPages = consultantLevelService.getConsultantLevelPages(pageNum, pageSize);
        return R.ok(consultantLevelPages);
    }
}
